/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.emex.app.stuff.gui.model;

import com.emex.app.shared.data.Provider;
import com.emex.app.stuff.provider.ProviderDataProvider;
import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;

/**
 *
 * @author Sergey Karavaev
 */
public class ProviderComboBoxModel extends AbstractListModel implements ComboBoxModel {
    
     /**
     * Currently selected car object.
     */
    private Provider selection;
    /**
     * Array of providers - needed to implement ComboBoxModel functionality.
     */
    private List<Provider> providers;


    public ProviderComboBoxModel() {
        providers = ProviderDataProvider.getInstance().getAllProviders();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setSelectedItem(Object anItem) {
        selection = (Provider) anItem;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object getSelectedItem() {
        return selection;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getSize() {
        return providers.size();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object getElementAt(int index) {
        return providers.get(index);
    }
}